package com.skyline.wo.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.skyline.base.type.Activity;
import com.skyline.wo.model.Photo;

/**
 * Photo RowMapper
 * 
 * @see RowMapper
 * @author wuqh
 * @version 1.00
 */
public class PhotoMapper implements RowMapper<Photo> {
	private static final PhotoMapper MAPPER = new PhotoMapper();

	public static final String COLUMN_ID = "id";
	public static final String COLUMN_OWNER_ID = "ownerId";
	public static final String COLUMN_OWNER_NICKNAME = "ownerNickname";
	public static final String COLUMN_OWNER_PORTRAIT = "ownerPortrait";
	public static final String COLUMN_ALBUM_ID = "albumId";
	public static final String COLUMN_ALBUM_NAME = "albumName";
	public static final String COLUMN_DESCRIPTION = "description";
	public static final String COLUMN_FILE = "file";
	public static final String COLUMN_MIDDLE_FILE = "middleFile";
	public static final String COLUMN_SMALL_FILE = "smallFile";
	public static final String COLUMN_EXT = "ext";
	public static final String COLUMN_SIZE = "size";
	public static final String COLUMN_ORDERNO = "orderNo";
	public static final String COLUMN_COMMENT_NUM = "commentNum";
	public static final String COLUMN_VISIT_NUM = "visitNum";
	public static final String COLUMN_UP = "up";
	public static final String COLUMN_DOWN = "down";
	public static final String COLUMN_SHARE_NUM = "shareNum";
	public static final String COLUMN_CREATE_TIME = "createTime";
	public static final String COLUMN_UPATE_TIME = "updateTime";
	public static final String COLUMN_AUTHORITY = "authority";
	public static final String COLUMN_ACTIVITY = "activity";

	public static PhotoMapper getMapper() {
		return MAPPER;
	}

	@Override
	public Photo mapRow(ResultSet rs, int rowNum) throws SQLException {
		Photo photo = new Photo();
		photo.setId(rs.getLong(COLUMN_ID));
		photo.setOwnerId(rs.getLong(COLUMN_OWNER_ID));
		photo.setOwnerNickname(rs.getString(COLUMN_OWNER_NICKNAME));
		photo.setOwnerPortrait(rs.getString(COLUMN_OWNER_PORTRAIT));
		photo.setAlbumId(rs.getLong(COLUMN_ALBUM_ID));
		photo.setAlbumName(rs.getString(COLUMN_ALBUM_NAME));
		try {
			photo.setDescription(rs.getString(COLUMN_DESCRIPTION));
		} catch (SQLException e) {
			photo.setDescription(null);
		}
		photo.setFile(rs.getString(COLUMN_FILE));
		photo.setMiddleFile(rs.getString(COLUMN_MIDDLE_FILE));
		photo.setSmallFile(rs.getString(COLUMN_SMALL_FILE));
		photo.setExt(rs.getString(COLUMN_EXT));
		photo.setSize(rs.getLong(COLUMN_SIZE));
		photo.setOrderNo(rs.getInt(COLUMN_ORDERNO));
		photo.setCommentNum(rs.getInt(COLUMN_COMMENT_NUM));
		photo.setVisitNum(rs.getInt(COLUMN_VISIT_NUM));
		photo.setUp(rs.getInt(COLUMN_UP));
		photo.setDown(rs.getInt(COLUMN_DOWN));
		photo.setShareNum(rs.getInt(COLUMN_SHARE_NUM));
		photo.setCreateTime(rs.getTimestamp(COLUMN_CREATE_TIME));
		photo.setUpdateTime(rs.getTimestamp(COLUMN_UPATE_TIME));
		photo.setAuthority(rs.getInt(COLUMN_AUTHORITY));
		photo.setActivity(Activity.valueOf(rs.getString(COLUMN_ACTIVITY)));
		return photo;
	}

}
